package day06;

import java.util.Scanner;
//有n位评委打分
public class CalTotalAvg {
    public static void main(String[] args) {
        Scanner sum =new Scanner(System.in);
        System.out.println("请输入评委人数");
        int people=sum.nextInt();
        double[] scores= inputData(people);//录入评委人数
        double avg =calAvg(scores);//计算平均分
        System.out.println("平均分为:"+avg);

    }
    /*该方法用于录入N位评委的评分*/
    public static double[] inputData(int n){
        //Random rand =new Random(100);
       double[] scores=new double[n];
       Scanner scan =new Scanner(System.in);
        for (int i = 0; i <scores.length ; i++) {
            System.out.println("请输入第"+(i+1)+"位评委的分数");
            scores[i]=scan.nextDouble();
        }
        return scores;
    }
    /*该方法用于计算平均分*/
    public static double calAvg(double[] scores){
        double total=0.0;
        double max =scores[0];
        double min =scores[0];
        for (int i=0;i< scores.length;i++){
            total+=scores[i]; //累加所有评分
            if (max<scores[i]){ //找最高分
                max=scores[i];
            }
            if (min>scores[i]){//找最低分
                min=scores[i];
            }
        }
     //计算平均分---总分减去最高分和最低分，再除以（评委数-2）
        double avg=(total-max-min)/ (scores.length-2);

        return avg;
    }
}
